export function debounce (func: { (): void; apply?: any; }, threshold: number, execAsap: boolean) {
    var timeout: string | number | NodeJS.Timeout | null | undefined;
    return function debounced(this: any) {
        var obj = this, args = arguments;
        function delayed() {
            if (!execAsap)
                func.apply(obj, args);
            timeout = null;
        };
        if (timeout)
            clearTimeout(timeout);
        else if (execAsap)
            func.apply(obj, args);
        timeout = setTimeout(delayed, threshold || 100);
    };
}